//
//  BKResultOfHistoryViewController.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/1.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKResultOfHistoryViewController.h"
#import "BKHistoryButton.h"
#import "BKHistoryViewModel.h"
#import "LoginViewController.h"
#import "BKColleageViewController.h"

@interface BKResultOfHistoryViewController ()
//@property (weak, nonatomic) IBOutlet BKHistoryButton *zhaosheng;
//@property (weak, nonatomic) IBOutlet BKHistoryButton *fenshu;
//@property (weak, nonatomic) IBOutlet BKHistoryButton *liuxue;
//@property (weak, nonatomic) IBOutlet BKHistoryButton *xuefei;
@property (weak, nonatomic) IBOutlet UIButton *nameButton;

@property (weak, nonatomic) IBOutlet UIView *contentView;

@end

@implementation BKResultOfHistoryViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [_nameButton setTitle:_name forState:UIControlStateNormal]; 
//    _fenshu.selected = YES;
    _historyScoreView = [[NSBundle mainBundle]loadNibNamed:@"BKHistoryScoreView" owner:self options:nil][0];
    
    _historyScoreView.cid = _cid;
    _historyScoreView.dataDic = _historyDic;
    
 /*   _zhaoshengView = [[NSBundle mainBundle]loadNibNamed:@"BKZhaoShengView" owner:self options:nil][0];
     _liuXueView = [[NSBundle mainBundle]loadNibNamed:@"BKLiuXueView" owner:self options:nil][0];
     _xuefeiZhuSuView = [[NSBundle mainBundle]loadNibNamed:@"BKXueFeiZhuSuView" owner:self options:nil][0];*/
    
    [_contentView addSubview:_historyScoreView];
   /* [_contentView addSubview:_zhaoshengView];
    [_contentView addSubview:_liuXueView];
    [_contentView addSubview:_xuefeiZhuSuView];*/
    
    //[_contentView bringSubviewToFront:_historyScoreView];
    
    [self.view layoutSubviews];
    
//    __weak BKResultOfHistoryViewController *weakSelf = self;
    
    
//    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
//    NSString *kq = @"北京";
//    if ([userDefaults objectForKey:@"kq"]) {
//        kq = [userDefaults objectForKey:@"kq"];
//        
//    }
    
    
    
//    [BKHistoryViewModel zhusuWithCid:_cid success:^(NSArray *dataArray) {
//        weakSelf.xuefeiZhuSuView.zhusuView.dataArray = dataArray;
//        
//    } failure:^(NSString *message) {
//        
//        if ([message isEqualToString:@"没有了"]) {
//            message =@"暂无招生计划数据";
//        }
//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
//        [alertView show];
//    }];
    
//    [BKHistoryViewModel xuefeiWithCid:_cid page:@"1" success:^(NSArray *dataArray) {
//        weakSelf.xuefeiZhuSuView.xuefeiView.dataArray = dataArray;
//        
//    } failure:^(NSString *message) {
//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
//        [alertView show];
//    }];
    
    }

- (void)viewWillLayoutSubviews{

    [_historyScoreView setFrame:CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height)];
 /*   [_zhaoshengView setFrame:CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height)];
    
    [_xuefeiZhuSuView setFrame:CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height)];
    
    [_liuXueView setFrame:CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height)];*/
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
- (IBAction)p_clickButton:(id)sender {
    
     __weak BKResultOfHistoryViewController *weakSelf = self;
     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *kq = @"北京";
    if ([userDefaults objectForKey:@"kq"]) {
        kq = [userDefaults objectForKey:@"kq"];
        
    }*/
//    _zhaosheng.selected = [sender isEqual:_zhaosheng];
//    _fenshu.selected = [sender isEqual:_fenshu];
//    _liuxue.selected = [sender isEqual:_liuxue];
//    _xuefei.selected = [sender isEqual:_xuefei];
    
 /*   if ([sender isEqual:_zhaosheng]) {
        [_contentView bringSubviewToFront:_zhaoshengView];
        [BKHistoryViewModel zhaoshengWithCid:_cid provid:_provid success:^(NSArray *dataArray){
            weakSelf.zhaoshengView.dataArray = dataArray;
        } failure:^(NSString *message) {
            
            if ([message isEqualToString:@"没有了"]) {
                message =@"暂无招生计划数据";
            }
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
            [alertView show];
            
        }];

        [_zhaoshengView.tableView reloadData];
        
    }
    
    if ([sender isEqual:_fenshu]) {
        
        [_contentView bringSubviewToFront:_historyScoreView];
        
        

    }
    
    if ([sender isEqual:_liuxue]) {
        
        [_contentView bringSubviewToFront:_liuXueView];
        [BKHistoryViewModel liuxueWithCid:_cid provid:kq
                                  success:^(NSArray *dataArray) {
                                      weakSelf.liuXueView.dataArray = dataArray;
                                  }
                                  failure:^(NSString *message) {
                                      if ([message isEqualToString:@"没有了"]) {
                                          message =@"暂无留学数据";
                                      }
                                      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
                                      [alertView show];
                                  }];
        [_liuXueView.tableView reloadData];
    }
    
    if ( [sender isEqual:_xuefei]) {
        [_contentView bringSubviewToFront:_xuefeiZhuSuView];
        [BKHistoryViewModel jiangxuejinWithCid:_cid success:^(NSArray *array) {
            
            weakSelf.xuefeiZhuSuView.dataArray = array;
            [weakSelf.xuefeiZhuSuView.tableView reloadData];
            
            
            
        } failure:^(NSString *message) {
            if ([message isEqualToString:@"没有了"]) {
                message =@"暂无奖学金信息";
            }
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
            [alertView show];
        }];
    }
    */
    
//}
- (IBAction)p_back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)p_collect:(id)sender {
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    if ([userDefaults objectForKey:@"Cookie"] !=nil) {
    
        [BKHistoryViewModel shoucangWithCid:_cid success:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"收藏成功" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
                [alertView show];});
            
           
        } failure:^(NSString *message) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
                [alertView show];
            });
           
        }];

    }else{
        LoginViewController *login = [[LoginViewController alloc] initWithNibName:NSStringFromClass([LoginViewController class]) bundle:nil];
        [self presentViewController:login animated:YES completion:nil];

    
    }
    
    
}
- (IBAction)p_xuexiao:(id)sender {
    
    BKColleageViewController *colleage = [[BKColleageViewController alloc] initWithNibName:NSStringFromClass([BKColleageViewController class]) bundle:nil];
    colleage.name= _name;
    colleage.cid = _cid;
    
    [self presentViewController:colleage animated:YES completion:nil];
}


@end
